package sprites;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.image.ImageObserver;

public class ImageSprite extends RectangleSprite implements ImageObserver {

	private Image	img = null;
	
	public ImageSprite(Point P, Dimension S, Image I) {
		super(P, S);
		setImg(I);
	}

	public Image getImg() {
		return img;
	}

	public void setImg(Image img) {
		this.img = img;
	}

	public void paintPoint(Graphics G, Rectangle R) {
		Color	oldColor = G.getColor();
		try {
			G.setColor(this.getColor());
			G.drawImage(getImg(), 
				R.x,							R.y,								// Position of the sprite we are drawing to 
				R.width*this.getBounds().width,	R.height*this.getBounds().height,	// Size of the sprite we are drawing the image into
				0,								0,									// Position within the image we are drawing prom
				getImg().getWidth(this),		getImg().getHeight(this),			// Size of the portion within the image we are drawing from (entire image)
				this.getColor(),													// Default background color
				this																// The observer that detected that the image has changed.
			);
		} catch (Exception e) {
			System.out.println(e.getLocalizedMessage());
		}
		G.setColor(oldColor);
	}

	@Override
	public boolean imageUpdate(Image img, int infoflags, int x, int y,	int width, int height) {
		return false;
	}

}
